/*
 * vertex.java
 *
 * Created on March 11, 2011, 2:56 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package ifs.RnD.Graph;

import ifs.RnD.revisionRead.RevisionGraph;
import ifs.RnD.revisionRead.Revision;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import ifs.RnD.svnRead.Tree;
import ifs.RnD.svnRead.DisplayRepositoryTree;
import java.util.Iterator;

/**
 *
 * @author anaklk
 */
public class RevVertex extends JLabel {

    boolean Final;
    private String value;
//to handel empty string *****************
    RevVertex parent = null;
    Edge e = null;
    Tree tree;
    DisplayRepositoryTree disRepoTree;
    String type;
    String revNO;
    Iterator iterator;
    RevisionGraph sd;

    /** Creates a new instance of vertex
     * @param revOb
     * @param revNo
     * @param x
     * @param y
     * @param sd
     */
    public RevVertex(final Revision revOb, String revNo, int x, int y, final RevisionGraph sd) {

        type = revOb.getType();
        setFont(new Font("tahoma", 0, 12));
        setText(revNo);

        setSize(100, 50);
        this.sd = sd;


        setToolTipText("<html>" + revOb.getType() + "<br>" + "Authour: " + revOb.getAuthor() + "<br>" + "Date: " + revOb.getDate() + "<br>" + revOb.getLogMsg() + "<br>" + revOb.getRecordUrl() + "</html>");


        if (type.equals("Added")) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/green-squerL8.png")));

        } else if (type.equals("Deleted")) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/red-ovalL8.png")));

        } else if (type.equals("Modified")) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/yel-diamondL8.png")));
        } else if (type.equals("Merge")) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/purple-ovalL8.png")));
        } else if (type.equals("Replace")) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/blue-rectangleL8.png")));
        } else if (type.equals("Expand")) {
            setText(" ");
            setFont(new Font("Dialog", 1, 14));
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/expandA1.jpg")));
            setToolTipText(null);

        } else {
            setIcon(new Oval(50, 50, 3));
        }

        setHorizontalTextPosition(RevVertex.HORIZONTAL);

        addMouseListener(new java.awt.event.MouseAdapter() {

            /**
             * changes label appearance and mouse pointer when mouse enter to a label.
             * @param
             * @exception Any exception
             * @return
             */
            public void mouseEntered(MouseEvent e) {
                Cursor cursor = Cursor.getDefaultCursor();
                //change cursor appearance to HAND_CURSOR when the mouse pointed on images
                cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
                setFont(new Font("tahoma", 1, 14));
                setCursor(cursor);
                sd.statusbar.setText("                node URL : " + revOb.getRecordUrl());


                if (type.equals("Added")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/green-squareDrk.png")));

                } else if (type.equals("Deleted")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/red-ovalDrk.png")));

                } else if (type.equals("Modified")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/yel-diamondDrk.png")));

                } else if (type.equals("Merge")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/purple-ovalDrk.png")));
                } else if (type.equals("Replace")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/blue-rectangleDrk.png")));
                } else if (type.equals("Expand")) {
                    setText(" ");
                    setFont(new Font("Dialog", 1, 14));
                    setToolTipText(null);
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/expandA1.jpg")));

                } else {
                    setIcon(new Oval(50, 50, 3));
                }

            }

            /**
             * reset label appearance and mouse pointer to the default when mouse exit from a label.
             * @param
             * @exception Any exception
             * @return
             */
            public void mouseExited(MouseEvent e) {
                setFont(new Font("tahoma", 0, 12));
                sd.statusbar.setText("                node URL : ");
                if (type.equals("Added")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/green-squerL8.png")));

                } else if (type.equals("Deleted")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/red-ovalL8.png")));
                } else if (type.equals("Modified")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/yel-diamondL8.png")));
                } else if (type.equals("Merge")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/purple-ovalL8.png")));
                } else if (type.equals("Replace")) {
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/blue-rectangleL8.png")));
                } else if (type.equals("Expand")) {
                    setText(" ");
                    setFont(new Font("Dialog", 1, 14));
                    setToolTipText(null);
                    setIcon(new javax.swing.ImageIcon(getClass().getResource("/ifs/RnD/Resources/expandA1.jpg")));
                } else {
                    setIcon(new Oval(50, 50, 3));
                }


            }
        });
    }

    /**
     * draw a oval on the label
     */
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        if (Final) {
            g.drawOval(5, 5, 40, 40);
        }
    }

    /**
     * sets the label name
     * @param text
     */
    public void setLableValue(String text) {
        value = text;
        setText(text);
    }

    /**
     * identifies the selected labe and gets its name
     * @param evt
     * @return
     */
    public String getSelectedNode(MouseEvent evt) {
        RevVertex ver = (RevVertex) evt.getSource();
        return ver.value;
    }
}
